function checkphone() {

    var phone = $("#phone").val();
    if (!(/^1[3456789]\d{9}$/.test(phone))) {
        layer.msg("手机号码有误，请重填");
        $("#phone").val("");
    }
}

function checkPwd() {
    var pwd = $("#newpassword").val();
    var reg = /^[a-zA-Z0-9]{4,10}$/;
    if (reg.test(pwd) == false) {
        layer.msg("密码不能含有非法字符，长度在4-10之间,大小写字母数字任意组合");
    }

}

//
function checkPwd2() {
    var pwd = $("#newpassword").val();
    var pwd2 = $("#newpassword2").val();
    var reg = /^[a-zA-Z0-9]{4,10}$/;

    if (reg.test(pwd2) == false) {
        layer.msg("密码不能含有非法字符，长度在4-10之间,大小写字母数字任意组合");
        return;
    }
    if (pwd != "" && pwd2 != "") {
        if (pwd2 != pwd) {
            layer.msg("两次输入不一致");
        }
    }
}

$(function () {

    layui.use('layer', function () {
        var layer = layui.layer;

        // layer.msg('hello');
    });

    $("#login").click(function () {

        var pwd = $("#newpassword").val();
        var pwd2 = $("#newpassword2").val();
        if (pwd != "" && pwd2 != "") {
            if (pwd2 != pwd) {
                layer.msg("新密码两次输入不一致");
                return;
            }
        }

        var formData = new FormData();
        formData.append('userName', $("#user").val());
        formData.append('password', $("#oldpassword").val());
        formData.append('phone', $("#phone").val());
        formData.append('newpwd1', $("#newpassword").val());
        formData.append('newpwd2', $("#newpassword2").val());
        formData.append('check', $("#check").val());
        $.ajax({
            url: "/user/changepwd",
            type: 'POST',
            data: formData,
            contentType: false,
            processData: false,
            cache: false,
            success: function (data) {
                if (data.success) {

                    layer.msg('改密成功');
                    /*
                     * if (!isEdit) { // 若为注册操作，成功后返回店铺列表页 window.location.href =
                     * "/o2o/shopadmin/shoplist"; }
                     */
                    setTimeout(function () {
                        window.location.href = "/info";
                    }, 700);

                } else {
                    layer.msg(data.msg);
                }
            }
        });
    })
})